package com.bigdata.vo;

import com.bigdata.mysql.entity.JkfwRole;
import com.bigdata.mysql.entity.JkfwUser;
import com.bigdata.mysql.entity.JkfwUserRole;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @ClassNameVoJkfwUser
 * @Description
 * @Author lly
 * @Date2020/3/22 18:00
 * @Version V1.0
 **/
public class VoJkfwUser {
    private String userId;

    private String username;

    private String password;

    private String salt;

    private String email;

    private String mobile;

    private Short status;
    private String createUserId;
    private Date createTime;
    private String name;
    private String roleids;

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public Short getStatus() {
        return status;
    }

    public void setStatus(Short status) {
        this.status = status;
    }

    public String getCreateUserId() {
        return createUserId;
    }

    public void setCreateUserId(String createUserId) {
        this.createUserId = createUserId;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getRoleids() {
        return roleids;
    }

    public void setRoleids(String roleids) {
        this.roleids = roleids;
    }

    public VoJkfwUser() {

    }

    public VoJkfwUser(JkfwUser user, List<JkfwUserRole> roles) {
        this.userId = user.getUserId();
        this.username = user.getUsername();
        this.password = user.getPassword();
        this.salt = user.getSalt();
        this.email = user.getEmail();
        this.mobile = user.getMobile();
        this.status = user.getStatus();
        this.createUserId = user.getCreateUserId();
        this.createTime = user.getCreateTime();
        this.name = user.getName();
        List<String> roleids = new ArrayList<>();
        for (JkfwUserRole role : roles) {
            roleids.add(role.getRoleId());
        }
        this.roleids = StringUtils.join(roleids, ",");
    }

    public JkfwUser covrJkfwUser() {
        JkfwUser user = new JkfwUser();
        user.setUserId(this.userId);
        user.setUsername(this.username);
        user.setPassword(this.password);
        user.setSalt(this.salt);
        user.setEmail(this.email);
        user.setMobile(this.mobile);
        user.setStatus(this.status);
        user.setCreateUserId(this.createUserId);
        user.setCreateTime(this.createTime);
        user.setName(this.name);
        return user;
    }
}
